package allenja.cp2011.MVC;

import java.sql.SQLException;

public class RunChatMVC {

	static int portNumber = 49696; // need to change this

	public RunChatMVC() {
		// Create the model, view and DAO
		MessageModel myModel = new MessageModel();
		MessageView myView = new MessageView();
		DerbyJdbcDAO myDAO = new DerbyJdbcDAO();

		// Add an observer to myView
		myModel.addObserver(myView);

		// Create the controller, add and initialise the model
		MessageController myController = new MessageController();
		myController.addModel(myModel);
		myController.initMessageModel(portNumber);

		// Add the DAO to the controller and initialise the database
		myController.addDAO(myDAO);
		myController.initDerbyDAO();

		// Add the view to the controller
		myController.addView(myView);

		// Add the controller to the view
		myView.addController(myController);
	}

	// Main ChatServer
	public static void main(String[] args) throws SQLException {
		@SuppressWarnings("unused")
		RunChatMVC runChat = new RunChatMVC();
	}
}
